

import java.io.IOException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import entities.RegisteredUser;
import sessionbeans.SearchBeanRemote;

/**
 * Servlet implementation class UnregisteredSearchServlet
 */
public class UnregisteredSearchServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UnregisteredSearchServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String ability = (String) request.getParameter("ability");
		if(ability != null){
			InitialContext context;
			try {
				context = new InitialContext();
				Object ref = context.lookup("SearchBeanRemote");
				SearchBeanRemote searchBean = (SearchBeanRemote)PortableRemoteObject.narrow(ref, SearchBeanRemote.class);
				List<RegisteredUser> results = searchBean.searchOnAll(ability);
				request.getSession().setAttribute("result",results);
			} catch (NamingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		response.sendRedirect("UnregisteredSearchPage.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
